package org.example.product.controller;
import org.example.product.entity.ResultBody;
import org.example.product.service.OrderManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/OrderManagement")
@CrossOrigin(origins="*")
public class OrderManController {
    @Autowired
    private OrderManService orderManService;
    //删除订单（管理员）
    @RequestMapping("/DeOrder")
    public ResultBody DeOrder(@RequestBody Map<String,Object> map) {
        if(map.get("code")==null)
            //订单编号
            return new ResultBody(404,"参数错误",false);
        String code = map.get("code").toString();
        if(orderManService.DeOrder(code)>0)
        {
            return new ResultBody(200,"删除订单成功",true);
        }
        else
            return new ResultBody(400,"删除订单失败",false);
    }
    //展示订单详细信息（管理员）
    @RequestMapping("/displayOrder")
    public ResultBody displayOrder() {
        return orderManService.displayOrder();
    }
    //展示订单详细信息（再准备支付时）
    @RequestMapping("/displayOrderDetailed")
    public ResultBody displayOrderDetailed(@RequestBody Map<String,Object> map) {
        if(map.get("code")==null||map.get("phone")==null) {
            //商品编号，用户电话号码
            return new ResultBody(404, "参数错误", false);
        }
        String phone = map.get("phone").toString();//用户电话号码
        String code = map.get("code").toString();//商品编号
        return orderManService.displayOrderDetailed(phone,code);
    }

}
